package com.bwf.forward;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @Version v1.0
 * @Description: TODO
 * @Author ZHANZHONGXIN
 * @Date 2022/6/8 14:50
 * @Copyright 博为峰
 */
public class ServletDemo01 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("ServletDemo01");
        req.setAttribute("servletName", "ServletDemo01");
        RequestDispatcher dispatcher = req.getRequestDispatcher("/f02");
        //请求转发
//        dispatcher.forward(req, resp);
        //请求包含
        dispatcher.include(req, resp);
        //响应头
        resp.setHeader("f01", "f01");
        //响应
        PrintWriter printWriter = resp.getWriter();
        printWriter.write("<h1>f01</h1>");
    }
}
